import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";

const buildForDebug = true;
function chunkRename(name: string): string {
  name = name.replace("@", "");
  if (name.slice(0, 7) === "ag-grid")
    name = "grid"
  else if (name.slice(0, 9) === "ag-charts")
    name = "charts"
  else if (name.slice(0, 4) === "gojs")
    name = "go"
  else
    name = "other";
  return name;
}
export default defineConfig({
  plugins: [solidPlugin()],
  build: {
    target: "esnext",
    reportCompressedSize: false,
    sourcemap: buildForDebug,
    minify: buildForDebug ? false : "esbuild",
    chunkSizeWarningLimit: 1100,
    rollupOptions: {
      output: {
        chunkFileNames: 'js/[name]-[hash].js',
        entryFileNames: 'js/[name]-[hash].js',
        assetFileNames: '[ext]/[name]-[hash].[ext]',
        manualChunks(id) {
          if (id.includes('node_modules')) {
            id = id.toString().split('node_modules/')[1].toString();
            let names = id.split('/').slice(0, 2);
            names[0] = chunkRename(names[0]);
            return names.join("-");
          }
        },
      }
    }
  },
  server: {
    proxy: {
      '/api': 'http://127.0.0.1/'
    }
  }
});